<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    姓名
    <input type="text" class="userName">
    年级
    <input type="number" class="age">
    性别
    <input type="number" class="gender">
    <button>增加一个人</button>

    <hr>
    <% for(var i=0;i<students.length;i++){ %>
        <div>
            <p><%= students[i].stuName %></p>
            <p> <%= students[i].stuAge  %> </p>
            <p><%= students[i].gender == 1 ? '女':'男'  %></p>
        </div>
    <%}%>



    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js"></script>
    <script>
        $("button").click(function(){
            $.ajax({
                url:"/addStu",
                type:'POST',
                dataType:"json",
                data:{
                    stuName:$(".userName").val(),
                    stuAge:$(".age").val(),
                    stuGender:$(".gender").val()
                },
                success:function(res){
                    console.log(res);
                    if(res.code === 0 ){
                        alert(res.msg)
                    }
                }
            });
        });
    </script>
</body>
</html>